# Create your views here.
from rest_framework.generics import ListAPIView
from rest_framework_extensions.cache.decorators import cache_response
from rest_framework_extensions.cache.mixins import CacheResponseMixin

from areas import serializers
from areas.models import Area


class AreaListProvinceView(ListAPIView):
	"""
	get province list
	"""
	queryset = Area.objects.filter(parent=None)
	serializer_class = serializers.AreaListSerializer

	# 加缓存有两种方法，一种是加装饰器，一种是继承类，下面的例子就是继承类
	@cache_response()
	def get(self, request, *args, **kwargs):
		return super().get(request, *args, **kwargs)


class AreaListCityView(CacheResponseMixin, ListAPIView):
	"""
	get city list
	"""
	serializer_class = serializers.AreaListSerializer

	def get_queryset(self):
		return Area.objects.filter(parent_id=self.kwargs['pk'])



